<?php

class html5av_time {

    static private $zone;

    static public function init() {
        self::$zone = get_option('timezone_string');
        if (self::$zone == '') {
            $zone = (int)get_option('gmt_offset');
            if ($zone < 1) {
                self::$zone = 'GMT-' . abs($zone);
            } else {
                self::$zone = 'GMT+' . abs($zone);
            }
        }
    }

    static public function getUTC($format = 'Y-m-d H:i:s') {
        $time = new DateTime();
        $timezone = new DateTimeZone('UTC');
        $time->setTimezone($timezone);
        return $time->format($format);
    }

    static public function utcToCurZone($time, $format = 'Y-m-d H:i:s') {
        $datetime = new DateTime();
        $timezone = new DateTimeZone('UTC');
        $datetime->setTimezone($timezone);
        if (method_exists($datetime, 'setTimestamp')) {
            $datetime->setTimestamp(strtotime($time));
        } else {
            $date = getdate((int) strtotime($time));
            $datetime->setDate($date['year'], $date['mon'], $date['mday']);
            $datetime->setTime($date['hours'], $date['minutes'], $date['seconds']);
        }
        $curzone = new DateTimeZone(self::$zone);
        $datetime->setTimezone($curzone);
        return $datetime->format($format);
    }

}

html5av_time::init();